<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单管理列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label id="orderNoLabel">提货单号：</label>
                            <input type="text" name="orderNo"/>
                        </li>
                        <li hidden="hidden">
                            <label>订单状态：</label>
                            <select name="orderStatus" th:with="type=${@dict.getType('b_order_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="add()" shiro:hasPermission="order:order:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="order:order:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="order:order:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="order:order:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table-order"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('order:order:edit')}]];
    var removeFlag = [[${@permission.hasPermi('order:order:remove')}]];
    var orderStatusDatas = [[${@dict.getType('b_order_type')}]];
    var contractId=[[${contractId}]];
    var contractType=[[${contractType}]];
    let supplierId=[[${supplierId}]];

    var prefix=ctx + "order/order";

    if(isBuyContractType()){
       $("#orderNoLabel").text("提货单号");
    }else{
        $("#orderNoLabel").text("销货单号");
    }
    let url=prefix + "/list";
    if(!isEmptyString(contractId)){
        url=prefix + "/list?contractId="+contractId+"&orderType="+contractType;
    }

    //采购合同
    function isBuyContractType(){
        if(contractType==contractTypeObj.buy){
            return true;
        }
        return false;
    }
    $(function() {
        var options = {
            id:"bootstrap-table-order",
            url: url,
            createUrl: prefix + "/add?contractId="+contractId+"&contractType="+contractType,
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export?contractId="+contractId+"&contractType="+contractType,
            sortName: "orderId",
            sortOrder:"desc",
            modalName: isBuyContractType()?"提货单管理":"销货单管理",
            columns: [{
                checkbox: true
            },
                {
                    field: 'orderId',
                    title: '订单id',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: isBuyContractType()?'提货单号':'销货单号',
                    formatter: function(value, row, index) {
                        return value;
                    }
                },

                {
                    field: 'orderStatus',
                    title: isBuyContractType()?'提货单状态':'销货单状态',
                    visible:false,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(orderStatusDatas, value);
                    }
                },
                {
                    field: 'totalNum',
                    title: isBuyContractType()?'提货单行数':'销货单行数'
                },
                {
                    field: 'totalPrice',
                    title: isBuyContractType()?'提货单总金额':'销货单总金额'
                },
                {
                    field: 'useMoney',
                    title: isBuyContractType()?'入库总金额':'出库总金额'
                },
                {
                    field: 'accountMoney',
                    title: isBuyContractType()?'入库已对账总金额':'出库已对账总金额'
                },
                {
                    field: 'payPrice',
                    visible: false,
                    title: isBuyContractType()?'提货单已支付总金额':'销货单已支付总金额'
                },
                {
                    field: 'receiptName',
                    title: '收货人姓名'
                },
                {
                    field: 'receiptPhone',
                    title: '收货人电话'
                },
                {
                    field: 'receiptAddress',
                    title: '收货详细地址'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                // {
                //     field: 'orderContent',
                //     title: isBuyContractType()?'提货单内容':'销货单内容'
                // },
                {
                    field: 'remark',
                    title: '备注'
                },  {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        let actions = [];
                        let title=isBuyContractType()?"提货详情":"销货详情";
                        actions.push('<a class="btn btn-dark btn-xs " href="javascript:void(0)" onclick="openContractOrderDetail(\'' + row.orderId + '\')"><i class="fa fa-search1"></i>'+title+'</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    //提货单详情
    function openContractOrderDetail(orderId){
        let title=isBuyContractType()?"提货详情":"销货详情";
        openWin(title,ctx+"warehouse/orderDetail?orderId="+orderId+"&contractType="+contractType);
    }

    //新增订单（提货单）
    function add() {
        table.set("bootstrap-table-order");
        let title=isBuyContractType()?"入库":"销货单";
        openWinRefresh(title,prefix + "/add?contractId="+contractId+"&contractType="+contractType+"&supplierId="+supplierId);
    }


</script>
</body>
</html>
